<template>
    <div id="exchangeGoods">
        <header>
            <div class="P_date">
                <span>时间：</span>
                <gDate @faithDate="faithDate"></gDate>
            </div>
            <div class="P_type">
                <div class="Choice">
                    <el-form ref="form">
                        <el-form-item label="活动区域">
                            <el-select v-model="handleChangeData" placeholder="请选择活动区域" @change="handleChange">
                                <el-option label='全部小程序' value='' >全部小程序</el-option>
                                <el-option :label=item.appname :value=item.appid v-for="(item,index) in options" :key="index"></el-option>
                            </el-select>
                        </el-form-item>
                        
                    </el-form>
                </div>
                <el-button @click="search">搜索</el-button>
            </div>
            <el-button type="primary" class="addBtn" @click="addBtn">添加</el-button>
        </header>
        <main>
            <el-table :data="tableData" border style="width: 100%" stripe>
                <el-table-column prop="id" label="ID"></el-table-column>
                <el-table-column prop="sort" label="排序"></el-table-column>
                <el-table-column prop="appname" label="小程序名字"></el-table-column>
                <el-table-column prop="logo" label="图片">
                    <template slot-scope="scope">
                        <el-popover trigger="hover" placement="top">
                            <p>{{scope.row.logo}}</p>
                            <div slot="reference">
                                <img :src=scope.row.logo alt="">
                            </div>
                        </el-popover>
                    </template>
                </el-table-column>
                
                <el-table-column prop="name" label="商品名称"></el-table-column>
                <el-table-column prop="price" label="原价"></el-table-column>
                <el-table-column prop="exchangeGoldNum" label="兑换金币数"></el-table-column>
                <el-table-column prop="exchangeUpperLimit" label="每日兑换上限"></el-table-column>
                <el-table-column prop="createdate" label="添加时间"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button @click="modifyClick(scope.row.id)" type="text" size="small">修改</el-button>
                        <el-button type="text" size="small" @click="removeClick(scope.row.id)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="currPage">
                <el-pagination
                    layout="prev, pager, next"
                    :page-size=pageSize
                    :current-page=currentPage
                    @current-change="handleCurrentChange"
                    :total=total>
                </el-pagination>
            </div>
        </main>
    </div>
</template>
<script>
import Vue from 'vue'
import exchangeGoodsModify  from '../modify/exchangeGoodsModify'
import exchangeGoodsAdd  from '../add/exchangeGoodsAdd'
import gDate from '../G_Date/gdate'
import { iframe,addList,ModifyList,RemoteList,DataList,getChannel } from '@/assets/js'
export default {
    data(){
        return {
            currentPage:1,//分页
            tableData:[],
            options:[],//联动菜单
            total:0,
            pageSize:2,
            props:{
                value: 'appid',
                label:"appname"
            },
            handleChangeData:[],//下拉
            TimeData:[]//时间
        }
    },
    methods:{
        faithDate:function(e){
            this.TimeData = e
        },
        handleChange:function(e){//触发下拉
            this.handleChangeData = e
        },
        search:function(){
            this.currentPage = 1
            this.CurrData()
        },
        addBtn:function(e){//添加
            addList(this,exchangeGoodsAdd)
        },
        modifyClick:function(e){//修改
            let obj = {}
            this.tableData.map((item,index)=>{
                if(item.id == e){
                    obj.id = item.id
                    obj.appid = item.appid
                    obj.appname = item.appname
                    obj.logo = item.logo
                    obj.name = item.name
                    obj.price = item.price
                    obj.num = item.exchangeGoldNum
                    obj.limit = item.exchangeUpperLimit
                    obj.sort = item.sort
                    return obj
                }
            })
            ModifyList(this,obj,exchangeGoodsModify)
        },
        removeClick:function(e){//删除
            let data = {
                id:e
            }
           RemoteList(this,data,e,"exchange_goods/delGoods")
        },
        handleCurrentChange:function(e){//点击分页
            this.currentPage = e
            let appid = ''
            this.CurrData(appid,e)
        },
        CurrData:function(obj){//分
            let data = {
                appid:this.handleChangeData?this.handleChangeData:'',
                startTime:this.TimeData[0]?this.TimeData[0]:'',
                endTime:this.TimeData[1]?this.TimeData[1]:'',
                page:this.currentPage
            }
            DataList(this,data,'exchange_goods/exchangeGoods')
        }
    },
    mounted:function(){
        this.CurrData()
        getChannel(this)
    },
    components:{
        gDate
    }
}
</script>